package com.hospital.wx.service.Impl;

import com.hospital.wx.dao.LikesDao;
import com.hospital.wx.dao.RepliesDao;
import com.hospital.wx.service.RepliesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
public class RepliesServiceImpl implements RepliesService {
    @Autowired
    private RepliesDao repliesDao;

    @Autowired
    LikesDao likesDao;

    @Override
    public int addReply(Map param) {
        return repliesDao.addReply(param);
    }

    @Override
    public int deleteReply(Integer replyId) {
        try {
            //删除这条回复的点赞
            likesDao.deleteLikesByTargetId(replyId);

            //删除子回复的点赞
            likesDao.deleteByParentId(replyId);

            //删除子回复
            repliesDao.deleteByParentReplyId(replyId);

            //删除这条回复
            int rows = repliesDao.deleteById(replyId);

            return rows;
        } catch (Exception e) {
            log.error("删除回复失败: replyId={}", replyId, e);
            return 0;
        }
    }
}
